package com.sxds.wn.dao.ibatis;

import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.sxds.wn.dao.IbatisBaseDao;
import com.sxds.wn.exception.DataAccessException;
import com.sxds.wn.model.Page;

/**
 * Description: <p>ibatis扩展实现</p>
 * Content Desc:<p>ibatis扩展实现<p>
 * Copy Right of Personal Tangtao 2007-2020
 * @author Andy
 * @version 1.0 Create Date:@2009-9-11
 */
public abstract class AbstractIbatisDao extends SqlMapClientDaoSupport implements IbatisBaseDao {
	
	/* (non-Javadoc)
	 * @see com.cfets..dao.IbatisBaseDao#loadPage(com.cfets..model.Page, java.lang.String, java.lang.String, java.util.Map)
	 */
	public void loadPage(Page page, String statementCountName,String statementQueryName, Map params) throws DataAccessException {
		if( page==null ){
			throw new java.lang.IllegalArgumentException("page must not be null.");
		}
		if( page.isEnablePage() ){
			//获取记录总数
			int count = (Integer)getSqlMapClientTemplate().queryForObject(statementCountName, params);
			page.setTotalObjects(count);
			page.calculate();
		}
		//设置查询去间断
		params.put("firstResult", page.getQueryFirstResult());
		params.put("maxResults", page.getMaxResults());
		List results = getSqlMapClientTemplate().queryForList(statementQueryName,params);
		page.setResults(results);		
	}
	
}
